using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SilkSharp.src
{
	/*
	 * Convert input to a linear scale.
	 * 
	 * @author Jing Dai
	 * @author Dingxin Xu
	 */
	public class Silk_log2lin
	{
		/*
		 * Approximation of 2^() (very close inverse of Silk_lin2log.SKP_Silk_lin2log())
		 * Convert input to a linear scale.
		 * 
		 * @param inLog_Q7 Input on log scale
		 * @return
		 */
		static int SKP_Silk_log2lin( int inLog_Q7 )    /* I:    Input on log scale */
		{
			int _out, frac_Q7;

			if( inLog_Q7 < 0 )
			{
				return 0;
			}

			_out = ( 1 << ( inLog_Q7 >> 7 ) );

			frac_Q7 = inLog_Q7 & 0x7F;
			if( inLog_Q7 < 2048 )
			{
				/* Piece-wise parabolic approximation */
				_out = Silk_SigProc_FIX.SKP_ADD_RSHIFT( _out, Silk_SigProc_FIX.SKP_MUL( _out, Silk_macros.SKP_SMLAWB( frac_Q7, Silk_SigProc_FIX.SKP_MUL( frac_Q7, 128 - frac_Q7 ), -174 ) ), 7 );
			}
			else
			{
				/* Piece-wise parabolic approximation */
				_out = Silk_SigProc_FIX.SKP_MLA( _out, Silk_SigProc_FIX.SKP_RSHIFT( _out, 7 ), Silk_macros.SKP_SMLAWB( frac_Q7, Silk_SigProc_FIX.SKP_MUL( frac_Q7, 128 - frac_Q7 ), -174 ) );
			}
			return _out;
		}
	}
}
